/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System.Windows.Controls;
using System.Windows.Media;

namespace Oceanside
{
    /// <summary>
    /// Interaction logic for KeyPad.xaml
    /// </summary>
    public partial class KeyPad : UserControl
    {
        public delegate void NumericKeyCallbackDelType(int val);
        public delegate void OkCallbackDelType();
        public delegate void ClearCallbackDelType();		
        
        private NumericKeyCallbackDelType KeyCallback;
        private OkCallbackDelType OkCallback;
        private ClearCallbackDelType ClearCallback;
        
        public KeyPad()
        {
            this.InitializeComponent();
            button1.MouseDown += b1Click;
            button2.MouseDown += b2Click;
            button3.MouseDown += b3Click;
            button4.MouseDown += b4Click;
            button5.MouseDown += b5Click;
            button6.MouseDown += b6Click;
            button7.MouseDown += b7Click;
            button8.MouseDown += b8Click;
            button9.MouseDown += b9Click;
            button11.MouseDown += zeroClick;
            buttonOk.MouseDown += okClick;
            buttonCl.MouseDown += clearClick;
        }

        public void SetButtonBackgroundBrush(Brush brush)
        {
            button1.ButtonBackground = brush;
            button2.ButtonBackground = brush;
            button3.ButtonBackground = brush;
            button4.ButtonBackground = brush;
            button5.ButtonBackground = brush;
            button6.ButtonBackground = brush;
            button7.ButtonBackground = brush;
            button8.ButtonBackground = brush;
            button9.ButtonBackground = brush;
            button11.ButtonBackground = brush;
            buttonOk.ButtonBackground = brush;
            buttonCl.ButtonBackground = brush;
        }

        public void SetButtonBackgroundMouseDownBrush(Brush brush)
        {
            button1.ButtonBackgroundMouseDown = brush;
            button2.ButtonBackgroundMouseDown = brush;
            button3.ButtonBackgroundMouseDown = brush;
            button4.ButtonBackgroundMouseDown = brush;
            button5.ButtonBackgroundMouseDown = brush;
            button6.ButtonBackgroundMouseDown = brush;
            button7.ButtonBackgroundMouseDown = brush;
            button8.ButtonBackgroundMouseDown = brush;
            button9.ButtonBackgroundMouseDown = brush;
            button11.ButtonBackgroundMouseDown = brush;
            buttonOk.ButtonBackgroundMouseDown = brush;
            buttonCl.ButtonBackgroundMouseDown = brush;
        }

        public void SetButtonBorderBrush(Brush brush)
        {
            button1.ButtonBorderBrush = brush;
            button2.ButtonBorderBrush = brush;
            button3.ButtonBorderBrush = brush;
            button4.ButtonBorderBrush = brush;
            button5.ButtonBorderBrush = brush;
            button6.ButtonBorderBrush = brush;
            button7.ButtonBorderBrush = brush;
            button8.ButtonBorderBrush = brush;
            button9.ButtonBorderBrush = brush;
            button11.ButtonBorderBrush = brush;
            buttonOk.ButtonBorderBrush = brush;
            buttonCl.ButtonBorderBrush = brush;
        }

        public void SetNumbersTextColorBrush(Brush brush)
        {
            button1.ButtonTextColor = brush;
            button2.ButtonTextColor = brush;
            button3.ButtonTextColor = brush;
            button4.ButtonTextColor = brush;
            button5.ButtonTextColor = brush;
            button6.ButtonTextColor = brush;
            button7.ButtonTextColor = brush;
            button8.ButtonTextColor = brush;
            button9.ButtonTextColor = brush;
            button11.ButtonTextColor = brush;
        }

        public void SetOkTextColor(Brush brush)
        {
            buttonOk.ButtonTextColor = brush;
        }

        public void SetClTextColor(Brush brush)
        {
            buttonCl.ButtonTextColor = brush;
        }

        public void SetNumericKeyCallbackDel(NumericKeyCallbackDelType del)
        {
            KeyCallback += del;
        }
        
        public void SetOkKeyCallbackDel(OkCallbackDelType del)
        {
            OkCallback += del;
        }

        public void SetClearKeyCallbackDel(ClearCallbackDelType del)
        {
            ClearCallback += del;
        }
        
        private void b1Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(1);
        }

        private void b2Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(2);
        }

        private void b3Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(3);
        }

        private void b4Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(4);
        }

        private void b5Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(5);
        }

        private void b6Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(6);
        }

        private void b7Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(7);
        }

        private void b8Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(8);
        }

        private void b9Click(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(9);
        }

        private void clearClick(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            ClearCallback();
        }

        private void zeroClick(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            KeyCallback(0);
        }

        private void okClick(object sender, System.Windows.RoutedEventArgs e)
        {
            e.Handled = true;
            OkCallback();
        }					
    }
}
